# -*- coding: utf-8 -*-

from abc import ABC, abstractmethod

from dtcloud.models import Model
from dtcloud.fields import Field

converts = {}


class Convert(ABC):
    field_type: str

    @classmethod
    def __init_subclass__(cls):
        super().__init_subclass__()
        converts[cls.field_type] = cls

    @classmethod
    @abstractmethod
    def to_read(cls, rec: Model, field: Field, **kwargs):
        pass

    @classmethod
    @abstractmethod
    def to_field(cls, value, metadata=None, update=False):
        """
        :param value: 前端传过来的值
        :param metadata: 元数据
        :param update: 是否是更新操作
        """
        pass

    @classmethod
    @abstractmethod
    def to_domain(cls, field, value, **kwargs):
        pass
